package com.huluobo.hyj.hyjmodel.data.db

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import com.huluobo.hyj.hyjmodel.KotlinApplication
import org.jetbrains.anko.db.*

class DatabaseHelper(ctx : Context  =  KotlinApplication.instance)
    :ManagedSQLiteOpenHelper(ctx,NAME,null,VERSION) {

    companion object{
        const val NAME = "im.db"
        const val VERSION = 1
    }

    override fun onCreate(db: SQLiteDatabase?) {
        //创建数据库 创建表
        db?.createTable(
           ContacTable.NAME, //表名
            true, // 是否是存在当前数据库
            ContacTable.ID to INTEGER + PRIMARY_KEY + AUTOINCREMENT, // id代表 主键 自增
            ContacTable.CONTACT to TEXT //字段
        )
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        db?.dropTable(ContacTable.NAME,true)
        onCreate(db)
    }

}